#ifndef XSAN_LIST_ITER_H
#define XSAN_LIST_ITER_H

#include "xsan_list.h"

#ifdef __cplusplus
extern "C" {
#endif

// Iterator structure for list traversal
typedef struct xsan_list_iter {
    xsan_list_t *list;
    xsan_list_node_t *current;
    xsan_list_node_t *next;
} xsan_list_iter_t;

/**
 * Initializes a list iterator.
 * The iterator should be initialized before its first use with xsan_list_iter_next.
 *
 * @param list The list to iterate over. Must not be NULL.
 * @param iter Pointer to the iterator structure to initialize. Must not be NULL.
 */
void xsan_list_iter_init(xsan_list_t *list, xsan_list_iter_t *iter);

/**
 * Advances the iterator to the next value in the list.
 * The first call after initialization returns the first value.
 *
 * @param iter The iterator, previously initialized with xsan_list_iter_init. Must not be NULL.
 * @param value_out Pointer to a void pointer where the value will be stored. Can be NULL if value is not needed.
 * @return true if a value was found and stored in *value_out, false if there are no more values or if iter is NULL.
 */
bool xsan_list_iter_next(xsan_list_iter_t *iter, void **value_out);

/**
 * Removes the current element from the list during iteration.
 * This function removes the element that was returned by the last call to xsan_list_iter_next.
 * The iterator will continue from the next element after the removed one.
 *
 * @param iter The iterator. Must not be NULL and must have been used with xsan_list_iter_next.
 * @return XSAN_OK on success, XSAN_ERROR_INVALID_PARAM if iter is NULL or no current element,
 *         or other error codes from the list removal operation.
 */
xsan_error_t xsan_list_iter_remove(xsan_list_iter_t *iter);

#ifdef __cplusplus
}
#endif

#endif // XSAN_LIST_ITER_H 